﻿using System.ServiceModel;
using ApiConceptsFramework.FluentApi;
using Microsoft.Ccr.Core;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using XcoAppSpaces.Core;

namespace test.ApiConceptsFramework.FluentApi
{
	[TestFixture, Explicit]
	class ScenarioTests
	{
		[Test]
		public void EvaluateAppSpace()
		{
			const int prevUsages = 0;

			var eval = new ApiEvaluator(typeof(XcoAppSpace).Assembly, typeof(IPort).Assembly);
			//eval.PrepareOutputForLatexTable = true;
			eval.SetUsings("System", "XcoAppSpaces.Core", "Microsoft.Ccr.Core");
			eval.Instantiation(() => new XcoAppSpace("address"), 2, previousUsages: prevUsages);
			eval.ConfigString("tcp.port=8000", 2);
			eval.MethodCall((XcoAppSpace s) => s.Run<string>("echo", msg => Console.WriteLine("Echo: {0}", msg)), previousUsages: prevUsages, returnParameterIsUsed: false);
			eval.MethodCall((XcoAppSpace s) => s.Connect<string>("localhost:8000/echo"), previousUsages: prevUsages, returnParameterIsUsed: true);
			eval.MethodCall((Port<string> p) => p.Post("test"), previousUsages: prevUsages);

			eval.EvaluateAndPrintToConsole();
		}

		[Test]
		public void EvaluateWcf()
		{
			const int prevUsages = 0;
			
			var eval = new ApiEvaluator(typeof(ServiceHost).Assembly);
			eval.SetUsings("System", "System.ServiceModel");
			eval.SetAssemblyRefs(typeof(ServiceHost).Assembly);

			eval.Instantiation(() => new ServiceContractAttribute(), previousUsages: prevUsages);
			eval.Instantiation(() => new OperationContractAttribute(), previousUsages: prevUsages);
			eval.Instantiation(() => new ServiceBehaviorAttribute(), previousUsages: prevUsages);
			eval.PropertyAccess((ServiceBehaviorAttribute s) => s.InstanceContextMode, previousUsages: prevUsages);
			eval.Instantiation(() => new ServiceHost(typeof(string), new Uri("")), previousUsages: prevUsages);
			eval.MethodCall((ServiceHost s) => s.AddServiceEndpoint("", null, ""), previousUsages: prevUsages);
			eval.MethodCall((ServiceHost s) => s.Open(), previousUsages: prevUsages);
			eval.Instantiation(() => new NetTcpBinding(), 2, previousUsages: prevUsages);
			eval.Instantiation(() => new ChannelFactory<string>(null, ""), previousUsages: prevUsages);
			eval.MethodCall((ChannelFactory<string> c) => c.CreateChannel(), previousUsages: prevUsages);
			
			eval.EvaluateAndPrintToConsole();
		}
	}
}
